package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjCheckTemplateStaff;
import com.koron.css2.newProjectCenter.bean.query.PjCheckTemplateStaffQuery;
import com.koron.css2.newProjectCenter.mapper.PjCheckTemplateStaffMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.css2.systemManage.bean.OrgUserBean;
import com.koron.css2.systemManage.mapper.OrgUserMapper;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 工程报装-工程验收员工权限列表查询
 */
public class PjCheckTemplateStaffList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjCheckTemplateStaffMapper pjCheckTemplateStaffMapper = factory.getMapper(PjCheckTemplateStaffMapper.class);
            OrgUserMapper orgUserMapper = factory.getMapper(OrgUserMapper.class);
            PjCheckTemplateStaffQuery pjCheckTemplateStaffQuery = JsonUtils.objectToPojo(req.getData(),PjCheckTemplateStaffQuery.class);

            // 1. 查询数据
            List<PjCheckTemplateStaff> pjCheckTemplateStaffList = pjCheckTemplateStaffMapper.getList(pjCheckTemplateStaffQuery);
            // 1.1 checkStaff->checkStaffName
            if (pjCheckTemplateStaffList != null && pjCheckTemplateStaffList.size() > 0) {
                for (PjCheckTemplateStaff pjCheckTemplateStaff : pjCheckTemplateStaffList) {
                    OrgUserBean orgUserBean = orgUserMapper.selectByAccount(pjCheckTemplateStaff.getCheckStaff());
                    if (orgUserBean != null) {
                        pjCheckTemplateStaff.setCheckStaffName(orgUserBean.getUserName());
                    }
                }
            }
            // 2. 返回数据
            MessageBean<List> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程验收员工权限列表查询成功",List.class);
            messageBean.setData(pjCheckTemplateStaffList);
            return messageBean;
        } catch (Exception e) {
            logger.error("工程验收员工权限列表查询失败",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程验收员工权限列表查询失败",null);
        }
    }
}
